package org.inspiration.dudu.user.service.impl;

import lombok.RequiredArgsConstructor;
import org.inspiration.dudu.user.mapper.UserFollowMapper;
import org.inspiration.dudu.user.service.UserFollowService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserFollowServiceImpl implements UserFollowService {

    private final UserFollowMapper userFollowMapper;

    /**
     * 关注某个用户
     *
     * @param followerId  关注者的用户 ID
     * @param followingId 被关注者的用户 ID
     */
    @Override
    public void followUser(Long followerId, Long followingId) {
        userFollowMapper.createFollow(followerId, followingId);
    }

    /**
     * 取消关注某个用户
     *
     * @param followerId  关注者的用户 ID
     * @param followingId 被关注者的用户 ID
     */
    @Override
    public void unfollowUser(Long followerId, Long followingId) {
        userFollowMapper.deleteFollow(followerId, followingId);
    }

    /**
     * 获取某个用户关注的所有用户 ID 列表
     *
     * @param followerId 关注者的用户 ID
     * @return 关注的用户 ID 列表
     */
    @Override
    public List<Long> getFollowingUserIds(Long followerId, Integer pageNum, Integer pageSize) {
        return userFollowMapper.getFollowingUserIds(followerId, (pageNum - 1) * pageSize, pageSize);
    }

    /**
     * 获取某个用户的所有粉丝的用户 ID 列表
     *
     * @param followingId 被关注者的用户 ID
     * @return 粉丝的用户 ID 列表
     */
    @Override
    public List<Long> getFollowerUserIds(Long followingId, Integer pageNum, Integer pageSize) {
        return userFollowMapper.getFollowerUserIds(followingId, (pageNum - 1) * pageSize, pageSize);
    }

    /**
     * 判断一个用户是否关注了另一个用户
     *
     * @param followerId  关注者的用户 ID
     * @param followingId 被关注者的用户 ID
     * @return 如果关注返回 true，否则返回 false
     */
    @Override
    public boolean isFollowing(Long followerId, Long followingId) {
        return userFollowMapper.isFollowing(followerId, followingId) > 0;
    }
}
